package com.huangguolin.cloud.api.course.control;

import com.huangguolin.cloud.api.course.entity.ApiCourseSearchEntity;
import com.huangguolin.cloud.api.course.entity.ApiScheduleEntity;
import com.huangguolin.cloud.api.course.service.ApiCourseService;
import com.huangguolin.cloud.mybatis.entity.PtCourseEntity;
import com.huangguolin.cloud.mybatis.flexigrid.PagingEntity;
import com.huangguolin.cloud.spring.control.BaseController;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/api/course")
public class ApiCourseController extends BaseController {
    @Resource
    private ApiCourseService apiCourseService;
    private Logger logger = LogManager.getLogger(this.getClass());
    @RequestMapping("/queryCourseList")
    public List<PtCourseEntity> queryCourseList(PagingEntity paging, ApiCourseSearchEntity entity){
        List<PtCourseEntity> list = apiCourseService.queryCourseList(entity,paging);
    return list;
    }
    @RequestMapping("/queryCourseTotal")
    public String queryCourseTotal(ApiCourseSearchEntity entity){

        Integer total = apiCourseService.queryCourseTotal(entity);
        return totalJSON(total);
    }
    @RequestMapping("/delete")
    public String delete (String courseUuids) {
        logger.info("courseUuids:" + courseUuids);
        if(courseUuids == null){
            return failJSON("course.delete.fail");
        }
        apiCourseService.deleteCourse(courseUuids);
        return successJSON("course.delete.success");
    }

    @RequestMapping("/add")
    public String add (String courseUuids) {
        logger.info("courseUuids:" + courseUuids);
        if(courseUuids == null){
            return failJSON("course.add.fail");
        }
        apiCourseService.addCourse(courseUuids);
        return successJSON("course.add.success");
    }

    @RequestMapping("/onSubmit")
    public String onSubmit(ApiScheduleEntity entity){
        logger.info(entity);
        if(apiCourseService.onSubmit(entity)){
            return failJSON("course.add.fail");
        }
        return successJSON("course.add.success");
    }

}

